////////////////////////////////////////////////////////////////////////////////
/*! \file
 * \brief Memory declaration file for the output-object.
 * \author Ivo Wingelaar
 * \date 2011
 * \version 0.1.0
 * \copyright GNU Lesser General Public License v3
 */
////////////////////////////////////////////////////////////////////////////////

#ifndef __MYTH_MEMORY_OUTPUT_MEMORY_C_HPP_INCLUDED__
#define __MYTH_MEMORY_OUTPUT_MEMORY_C_HPP_INCLUDED__

#include "MythMemory.hpp"

namespace Myth
{
namespace Memory
{

////////////////////////////////////////////////////////////////////////////////
//! A memory implementation to an output of data.
class OutputMemory_C : public Stream::Output
{
public:
    ////////////////////////////////////////////////////////////////////////////
    //! Creates an output to a memory location.
    OutputMemory_C(const std::string& stream_name, void* memory, uintptr_t size, bool own_memory);

    ////////////////////////////////////////////////////////////////////////////
    //! Virtual destructor.
    virtual ~OutputMemory_C(void);

    ////////////////////////////////////////////////////////////////////////////
    //! Writes a number of bytes to an output.
    virtual uintptr_t write(const void* buffer, uintptr_t size);

    ////////////////////////////////////////////////////////////////////////////
    //! Changes the position in the data-output.
    virtual bool seek(uintptr_t position, bool relative = false);

    ////////////////////////////////////////////////////////////////////////////
    //! Returns the current position of the output.
    virtual uintptr_t get_pos(void) const;

private:
    ////////////////////////////////////////////////////////////////////////////
    // Member data
    ////////////////////////////////////////////////////////////////////////////

    void *mMemory;   ///< The pointer to the memory location.
    uint32_t mSize;  ///< The size of the memory chunk.
    uint32_t mPos;   ///< The current position in the stream.
    bool mOwnMemory; ///< Should the memory be deleted when the object is destroyed?
};

} // namespace Memory
} // namespace Myth

#endif // __MYTH_MEMORY_OUTPUT_MEMORY_C_HPP_INCLUDED__
